﻿using Microsoft.AspNetCore.Mvc;
using xxx.Candidates.System.Hostd.Authorization;
using xxx.Candidates.System.Interfaces.IService;
using xxx.Candidates.System.Model.View;

namespace xxx.Candidates.System.Hostd.Controllers.System
{
    [ApiController]
    [Route("api/[controller]")]
    [Authorization]
    public class CandidatesController : BaseController
    {
        private readonly IRandomCandidateService _generator;
        private readonly IReorderStrategy _reorderStrategy;

        public CandidatesController(
            IRandomCandidateService generator,
            IReorderStrategy reorderStrategy)
        {
            _generator = generator;
            _reorderStrategy = reorderStrategy;
        }

        [HttpGet("random")]
        public IActionResult GenerateRandom()
        {
            return toResponse(_generator.GenerateRandomCandidates(20));
        }

        [HttpPost("reorder")]
        public IActionResult Reorder([FromBody] IEnumerable<CandidateListVM> candidates)
        {
            return toResponse(_reorderStrategy.Reorder(candidates));
        }
    }
}
